class Student {
    static public class DataStringFormatException extends Exception {
        static final private String MESSAGE_HEADER = "This string does not meet the input format demand: ";
        private String errorString = "";

        public void setErrorString(String _string) {
            this.errorString = _string;
        }

        public String getMessage() {
            return MESSAGE_HEADER + this.errorString;
        }

        public DataStringFormatException() {
            super();
        }

        public DataStringFormatException(Throwable e) {
            super(e);
        }
    }

    static final int ELEMENT_COUNT = 5;
    static final int ID_POSITION = 0;
    static final int NAME_POSITION = 1;
    static final int GRADE_ONE_POSITION = 2;
    static final int GRADE_TWO_POSITION = 3;
    static final int GRADE_THREE_POSITION = 4;
    private String studentID = "";
    private String studentName = "";
    private int gradeCourseOne = 0;
    private int gradeCourseTwo = 0;
    private int gradeCourseThree = 0;

    static public Student parseString(String dataString) throws DataStringFormatException {
        String[] splitedString = dataString.split(",");
        if (ELEMENT_COUNT != splitedString.length) {
            DataStringFormatException e = new DataStringFormatException();
            e.setErrorString(dataString);
            throw e;
        }

        try {
            Student student = new Student();
            student.setStudentID(splitedString[ID_POSITION].trim());
            student.setStudentName(splitedString[NAME_POSITION].trim());
            student.setGradeCourseOne(Integer.parseInt(splitedString[GRADE_ONE_POSITION].trim()));
            student.setGradeCourseTwo(Integer.parseInt(splitedString[GRADE_TWO_POSITION].trim()));
            student.setGradeCourseThree(Integer.parseInt(splitedString[GRADE_THREE_POSITION].trim()));
            return student;
        } catch (NumberFormatException e) {
            DataStringFormatException newE = new DataStringFormatException(e);
            newE.setErrorString(dataString);
            throw newE;
        }
    }

    public String makeAverageGradeInfo() {
        return this.studentID + "\t\t" + this.studentName + "\t\t" + String.valueOf((this.gradeCourseOne + this.gradeCourseTwo + this.gradeCourseThree) / 3);
    }

    public String getStudentID() {
        return this.studentID;
    }

    public void setStudentID(String _id) {
        this.studentID = _id;
    }

    public String getStudentName() {
        return this.studentName;
    }

    public void setStudentName(String _name) {
        this.studentName = _name;
    }

    public int getGradeCourseOne() {
        return this.gradeCourseOne;
    }

    public void setGradeCourseOne(int _grade) {
        this.gradeCourseOne = _grade;
    }

    public int getGradeCourseTwo() {
        return this.gradeCourseTwo;
    }

    public void setGradeCourseTwo(int _grade) {
        this.gradeCourseTwo = _grade;
    }

    public int getGradeCourseThree() {
        return this.gradeCourseThree;
    }

    public void setGradeCourseThree(int _grade) {
        this.gradeCourseThree = _grade;
    }
}
